<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <#include "../../common/header.ftl">

    <link rel="stylesheet" href="${base}/res/js/bootstrap-fileinput/css/fileinput.min.css" crossorigin="anonymous">
    <script src="${base}/res/js/bootstrap-fileinput/js/fileinput.min.js" type="text/javascript"></script>
    <script src="${base}/res/js/bootstrap-fileinput/js/locales/zh.js" type="text/javascript"></script>
</head>
<body class="btn-body">
<input type="hidden" id="companyId" value="${companyId!}">
<div class="container-fluid">
    <#include "../../common/left-nav.ftl">
    <div class="main-box">
        <ol class="breadcrumb crumbs always-top">
            <li><a href="${base}/admin/company">企业管理</a></li>
            <li class="active">编辑</li>

            <div class="form-btns">
                <button type="submit" class="btn btn-primary btn-sm">
                    <span class="glyphicon glyphicon-floppy-disk"></span> 保存
                </button>

                <#if !companyId??>
                    <a href="${base}/admin/company" type="button" class="btn btn-danger btn-sm">
                        <span class="glyphicon glyphicon-remove"></span> 取消
                    </a>
                <#else>
                    <a href="${base}/admin/company/${companyId}" type="button" class="btn btn-danger btn-sm">
                        <span class="glyphicon glyphicon-remove"></span> 取消
                    </a>
                </#if>

            </div>
        </ol>

        <form class="form-horizontal" id="dataForm">

            <div class="container-fluid">
                <div class="detail-div">

                    <div class="panel panel-info panel-freight">
                        <div class="panel-heading"><b>基础信息</b></div>
                        <div class="panel-body">
                            <div class="details-panel">
                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">单位名称 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="unitName"
                                                   placeholder="请输入单位全称" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">税号 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="taxNo"
                                                   placeholder="请输入税务登记号" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">注册资金 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="registeredCapital" required
                                                   placeholder="请输入企业注册资金金额">
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">注册地</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="registration"
                                                   placeholder="请输入企业注册地址">
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">主营业务 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="business"
                                                   placeholder="请输入企业主营业务" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="practicing" class="col-sm-2 control-label">自有车队规模 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="scale" required
                                                   placeholder="请输入企业车队规模">
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="practicing" class="col-sm-2 control-label">主营线路 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="mainLine" required
                                                   placeholder="请输入主要营业线路">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="panel panel-info panel-freight">
                        <div class="panel-heading"><b>联系信息</b></div>
                        <div class="panel-body">
                            <div class="details-panel">
                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">管理账号 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="username" id="username"
                                                   placeholder="请输入管理员账号" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">联系人 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="contact"
                                                   placeholder="请输入企业联系人姓名" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">联系电话 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="tel"
                                                   placeholder="请输入企业联系电话" required>
                                        </div>
                                    </div>
                                </div>

                                <div class="item">
                                    <div class="form-group">
                                        <label for="carNumber" class="col-sm-2 control-label">企业地址 <span
                                                    class="required-span">*</span></label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" name="address" required
                                                   placeholder="请输入企业所在地址">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    var companyId;
    $(document).ready(function () {
        companyId = $('#companyId').val();
        if (companyId) {
            $.httpclient.get(API_COMPANY + '/' + companyId, {
                time: new Date().getTime()
            }, function (data) {
                if (data.code === 'SUCCESS') {
                    var formData = data.obj;
                    var basePath = $('#base').val() + '/';
                    $('#dataForm').find('input').each(function () {
                        if (formData[this.name]) {
                            this.value = formData[this.name];
                            var fileFlag = $(this).data('file-flag');
                            if (fileFlag && this.value) {
                                $('#' + fileFlag).attr('src', basePath + 'file/image/' + this.value);
                            }

                        }
                    });
                }
                $('#username').attr("disabled", true);
            })
        }

        $('#dataForm').submit(function (data) {
            var target = data.target;
            var formData = {};

            var fieldInputs = $(target).find('input');
            for (var i = 0; i < fieldInputs.length; i++) {
                var item = fieldInputs[i];
                if (item.name && item.name !== '') {
                    formData[item.name] = item.value;
                }
            }

            formData['id'] = companyId;
            if (companyId && companyId !== '') {
                $.httpclient.put(API_COMPANY, JSON.stringify(formData), function (data) {
                    location.href = ctx + '/admin/company/' + companyId;
                })
            } else {
                $.httpclient.post(API_COMPANY, JSON.stringify(formData), function (data) {
                    location.href = ctx + '/admin/company/' + data.obj.id;
                })
            }
            return false;
        });
    })
</script>
